{php $newUI = true;}
{template 'common/header'}
<ul class="nav nav-tabs">
	<li class="active"><a href="{php echo url('mc/uc')}"><i class="icon-user"></i> UC站点整合</a></li>
</ul>
<div class="main">
	<form id="form1" action="{php echo url('mc/uc')}" method="post" class="form-horizontal form ng-cloak"  ng-controller="ucSetting">
		<div class="panel panel-default">
			<div class="panel-heading">
				设置UC参数
			</div>
			<div class="panel-body">
				<div class="alert alert-info">
					<p>
						使用UC能够整合其他系统的会员信息. 如果你不清楚此功能的作用, 请咨询您的技术人员. <br />
						1. 在UC系统中增加新的应用, 并填写[应用接口文件名称]为: uc.php?uniacid={$_W['uniacid']} <br />
						2. 在下方启用UC, 并按照UC系统中新增的应用参数填写
					</p>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">启用UC</label>
					<div class="col-sm-8 col-xs-12">
						<label class="radio-inline">
							<input type="radio" id="status1" name="status" ng-model="uc.status" value="1"/>
							开启
						</label>
						<label class="radio-inline">
							<input type="radio" id="status0" name="status" ng-model="uc.status" value="0"/>
							关闭
						</label>
						<span class="help-block">使用UC能够整合其他系统的会员信息. 如果你不清楚此功能的作用, 请咨询您的技术人员.</span>
					</div>
				</div>
				<div  ng-show="uc.status == '1'">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">快速录入</label>
						<div class="col-sm-8 col-xs-12">
							<textarea class="form-control" rows="6" id="textarea"></textarea>
							<span class="help-block">你可以直接复制UC中的[应用的 UCenter 配置信息]来快速搞定配置参数.</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
						<div class="col-sm-8 col-xs-12">
							<input id="submit" type="button" class="btn btn-primary" value="一键录入">
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">通行证名称</label>
						<div class="col-sm-8 col-xs-12">
							<input type="text" name="title" class="form-control" value="{{uc.title}}" autocomplete="off">
							<span class="help-block">请输入你的通行证名称, 方便与UC系统联系.比如: 你的论坛名字</span>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">应用ID</label>
						<div class="col-sm-8 col-xs-12">
							<input type="text" name="appid" class="form-control" value="{{uc.appid}}" autocomplete="off">
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">通信密钥</label>
						<div class="col-sm-8 col-xs-12">
							<input type="text" name="key" class="form-control" value="{{uc.key}}" autocomplete="off"/>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">UCenter字符集</label>
						<div class="col-sm-8 col-xs-12">
							<input type="text" name="charset" class="form-control" value="{{uc.charset}}" autocomplete="off"/>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">通信方式</label>
						<div class="col-sm-8 col-xs-12">
							<label class="radio-inline">
								<input type="radio" name="connect" ng-model="uc.connect" value="mysql"/>
								MYSQL方式
							</label>
							<label class="radio-inline">
								<input type="radio" name="connect" ng-model="uc.connect" value="http"/>
								远程方式HTTP
							</label>
						</div>
					</div>
					<div class="tb mysql" ng-show="uc.connect == 'mysql';">
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">数据库主机</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbhost" class="form-control" value="{{uc.dbhost}}" autocomplete="off">
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">数据库用户名</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbuser" class="form-control" value="{{uc.dbuser}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">数据库密码</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbpw" class="form-control" value="{{uc.dbpw}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">数据库名称</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbname" class="form-control" value="{{uc.dbname}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">数据库字符集</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbcharset" class="form-control" value="{{uc.dbcharset}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">表前缀</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="dbtablepre" class="form-control" value="{{uc.dbtablepre}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否持久连接</label>
							<div class="col-sm-8 col-xs-12">
								<label class="radio-inline">
									<input type="radio" name="dbconnect" value="1" ng-model="uc.dbconnect"/>
									是
								</label>
								<label class="radio-inline">
									<input type="radio" name="dbconnect" value="0" ng-model="uc.dbconnect"/>
									否
								</label>
							</div>
						</div>
					</div>
					<div class="tb http" ng-show="uc.connect != 'mysql';">
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">服务端URL地址</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="api" class="form-control" value="{{uc.api}}" autocomplete="off"/>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">服务端IP</label>
							<div class="col-sm-8 col-xs-12">
								<input type="text" name="ip" class="form-control" value="{{uc.ip}}" autocomplete="off"/>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />
			<input type="hidden" name="token" value="{$_W['token']}" />
		</div>
	</form>
</div>
<script type="text/javascript">
	angular.module('app', []).controller('ucSetting', function($scope, $http) {
		$scope.uc = {php echo json_encode($uc);};
	});
	angular.bootstrap(document, ['app']);
	//处理快速录入
	$("#submit").click(function(){
		var textarea = $("#textarea").val();
		var arr = textarea.split(';');
		var data = new Array();
		for(var i in arr) {
			var index0 = arr[i].indexOf("UC");
			var index1 = arr[i].indexOf("', '");
			var index2 = arr[i].indexOf("')");
			var key = arr[i].substring(index0,index1);
			var value = arr[i].substring(index1+4,index2);
			data[key] = value;
		}
		var $scope = angular.element('#form1').scope();
		$scope.uc.connect = data['UC_CONNECT'];
		$scope.uc.appid = data['UC_APPID'];
		$scope.uc.key = data['UC_KEY'];
		$scope.uc.charset = data['UC_CHARSET'];
		$scope.uc.dbhost = data['UC_DBHOST'];
		$scope.uc.dbuser = data['UC_DBUSER'];
		$scope.uc.dbname = data['UC_DBNAME'];
		$scope.uc.dbpw = data['UC_DBPW'];
		$scope.uc.dbcharset = data['UC_DBCHARSET'];
		$scope.uc.dbtablepre = data['UC_DBTABLEPRE'];
		$scope.uc.dbconnect = data['UC_DBCONNECT'];
		$scope.uc.api = data['UC_API'];
		$scope.uc.ip = data['UC_IP'];
		
		$scope.$digest();
	});
	$("#form1").submit(function(){
		if($(':radio[name="status"]:checked').val()=='1'){
			if($.trim($(':text[name="title"]').val()) == '') {
				util.message('必须输入通行证名称.', '', 'error');
				return false;
			}
			var appid = parseInt($(':text[name="appid"]').val());
			if(isNaN(appid)) {
				util.message('必须输入UCenter应用的ID.', '', 'error');
				return false;
			}
			if($.trim($(':text[name="key"]').val()) == '') {
				util.message('必须输入与UCenter的通信密钥.', '', 'error');
				return false;
			}
			if($.trim($(':text[name="charset"]').val()) == '') {
				util.message('必须输入UCenter的字符集.', '', 'error');
				return false;
			}
			if($(':radio[name="connect"]:checked').val() == 'mysql') {
				if($.trim($(':text[name="dbhost"]').val()) == '') {
					util.message('必须输入UCenter数据库主机地址.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="dbuser"]').val()) == '') {
					util.message('必须输入UCenter数据库用户名.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="dbpw"]').val()) == '') {
					util.message('必须输入UCenter数据库密码.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="dbname"]').val()) == '') {
					util.message('必须输入UCenter数据库名称.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="dbcharset"]').val()) == '') {
					util.message('必须输入UCenter数据库字符集.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="dbtablepre"]').val()) == '') {
					util.message('必须输入UCenter数据表前缀.', '', 'error');
					return false;
				}
			} else if($(':radio[name="connect"]:checked').val() == 'http'){
				if($.trim($(':text[name="api"]').val()) == '') {
					util.message('必须输入UCenter 服务端的URL地址.', '', 'error');
					return false;
				}
				if($.trim($(':text[name="ip"]').val()) == '') {
					util.message('必须输入UCenter的IP.', '', 'error');
					return false;
				}
			}
		}
	});
</script>
{template 'common/footer'}
